import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { isOrgExist as isDealerExist } from '@/views/mds/dealer/Org.api';
import { isOrgExist as isTerminalExist } from '@/views/mds/terminal/Org.api';
// import { ref } from 'vue';
// import { trim } from 'lodash-es';
// import { rules } from '/@/utils/helper/validator';
// import { render } from '/@/utils/common/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: '经销商ID',
    dataIndex: 'ownerAscId',
    sorter: true,
  },
  {
    title: '经销商名称',
    dataIndex: 'ownerAscName',
  },
  {
    title: '终端ID',
    dataIndex: 'partnerAscId',
    sorter: true,
  },
  {
    title: '终端名称',
    dataIndex: 'partnerAscName',
  },
  {
    title: '终端原始名称',
    dataIndex: 'name',
    sorter: true,
  },
  {
    title: '省份',
    dataIndex: 'province',
  },
  {
    title: '城市',
    dataIndex: 'city',
  },
  {
    title: '区县',
    dataIndex: 'county',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '经销商名称',
    field: 'ownerAscName',
    component: 'Input',
  },
  {
    label: '终端名称',
    field: 'partnerAscName',
    component: 'Input',
  },
  {
    label: '原始终端名称',
    field: 'name',
    component: 'Input',
  },
];
export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  {
    label: '经销商名称',
    field: 'ownerAscName',
    component: 'Input',
    rules: [
      {
        required: true,
        message: '请输入经销商名称',
      },
      {
        validator(_, value) {
          return new Promise((resolve, reject) => {
            isDealerExist(value)
              .then(() => resolve())
              .catch((err) => {
                reject(err.message || '验证失败');
              });
          });
        },
      },
    ],
  },
  {
    label: '终端名称',
    field: 'partnerAscName',
    component: 'Input',
    rules: [
      {
        required: true,
        message: '请输入终端名称',
      },
      {
        validator(_, value) {
          return new Promise((resolve, reject) => {
            isTerminalExist(value)
              .then(() => resolve())
              .catch((err) => {
                reject(err.message || '验证失败');
              });
          });
        },
      },
    ],
  },
  {
    label: '原始终端名称',
    field: 'name',
    component: 'Input',
    required: true,
  },
];
